#ifndef __HTTPRESPONSE_H__
#define __HTTPRESPONSE_H__

#include <string>
#include <unordered_map>
#include <sstream>

using std::string;
using std::unordered_map;

enum class HttpStatusCode {
    OK = 200,
    CREATED = 201,
    NO_CONTENT = 204,
    BAD_REQUEST = 400,
    UNAUTHORIZED = 401,
    FORBIDDEN = 403,
    NOT_FOUND = 404,
    METHOD_NOT_ALLOWED = 405,
    INTERNAL_SERVER_ERROR = 500,
    NOT_IMPLEMENTED = 501,
    SERVICE_UNAVAILABLE = 503
};

class HttpResponse {
public:
    HttpResponse();
    ~HttpResponse();
    
    // 设置响应状态
    void setStatusCode(HttpStatusCode code);
    void setStatusCode(int code, const string &reason = "");
    
    // 设置响应头
    void setHeader(const string &name, const string &value);
    void addHeader(const string &name, const string &value);
    string getHeader(const string &name) const;
    bool hasHeader(const string &name) const;
    
    // 设置响应体
    void setBody(const string &body);
    void appendBody(const string &content);
    const string& getBody() const { return _body; }
    
    // 便利方法
    void setContentType(const string &contentType);
    void enableCORS();
    void setJsonContent(const string &json);
    void setHtmlContent(const string &html);
    void setPlainTextContent(const string &text);
    void setFileContent(const string &filePath);
    
    // 构建响应字符串
    string buildResponse() const;
    
    // 重置
    void reset();
    
    // 工具方法
    string getStatusText(HttpStatusCode code) const;

private:
    void setDefaultHeaders();

private:
    HttpStatusCode _statusCode;
    string _customReason;
    unordered_map<string, string> _headers;
    string _body;
    string _version;
};

#endif